package practice1_100;

public class Practice617 {
    public TreeNode mergeTrees(TreeNode root1, TreeNode root2) {
        //涉及树就递归，先考虑终止条件
        if (root1==null&&root2==null) return null;
        if(root1==null&&root2!=null) return root2;
        if(root2==null&&root1!=null) return root1;

        //当前要做的事情
        TreeNode root=new TreeNode(0);
        root.val=root1.val+ root2.val;
        //抛给下一层去处理
        root.left= mergeTrees(root1.left,root2.left);
        root.right= mergeTrees(root1.right,root2.right);
        //return 值
        return root;
    }
}
